home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
c
/
ultratk.exe
/
VIDEO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-19
|
4KB
|
138 lines
/* video.c */
#include <conio.h> /* MONO, BW80, etc are here */
#include <dos.h> /* MK_FP */
#include "video.h"
video_status CRT; /* a global var */
int get_video_status ( void )
{
/* This function updates the global structure CRT */
int area; /* scratch var */
CRT.mode = *(char far *) 0x449;
if ( CRT.mode==MONO ) CRT.location = 0xb000;
else if ( CRT.mode > 3 ) return (1);/* no graphic modes allowed */
else CRT.location = 0xb800;
CRT.attr = *(char far *) MK_FP ( CRT.location, 1 );
CRT.color = !((CRT.mode==BW40)||(CRT.mode==BW80)||(CRT.mode==MONO));
CRT.cols = *( int far *) 0x44a;
area = *(int far *) 0x44c;
CRT.rows = area / CRT.cols / 2;
CRT.rows = ( CRT.rows >= 63 ) ? 63 :\
( CRT.rows >= 60 ) ? 60 :\
( CRT.rows >= 50 ) ? 50 :\
( CRT.rows >= 44 ) ? 44 :\
( CRT.rows >= 43 ) ? 43 :\
( CRT.rows >= 36 ) ? 36 :\
( CRT.rows >= 34 ) ? 34 : 25;
return (0);
}
void put_char ( char c )
{
/* This function is bios service 14: it writes a char to the current
cursor position using the current attribute, then updates the cursor
position. It is faster than putchar() and better behaved than putch().
*/
_BH = 0; /* page 0 */
_AL = c; /* char to write */
_AH = 14; /* request func 14 */
geninterrupt (0x10); /* video services */
}
int put_string ( char *string, int attribute, int row, int col )
{
/* This function writes a string to a specific video location and also
lets the user specify an attribute. However, it defaults to the
current cursor position and attribute. E.G. put_string ("Hi",0,0,0);
*/
char far *location;
int offset, len=0;
if (( col > CRT.cols )||( row > CRT.rows )) return (1);
if ( attribute==0 ) attribute = CRT.attr;
if (( col==0 )||( row==0 )) {
_BH = 0; /* page 0 */
_AH = 3; /* read cursor position */
geninterrupt (0x10); /* video services */
col = _DL+1;
row = _DH+1;
}
offset = (row-1) * CRT.cols * 2 + (col-1) * 2;
location= (char far*) MK_FP ( CRT.location, offset );
while ( *string ) {
*location++ = *string++; /* put a char, increment both */
*location++ = attribute; /* put attribute, increment location again */
len++; /* increment string length count */
}
goto_rc ( row, col+len ); /* update the cursor position */
return (0);
}
void clear_screen ( void )
{
_BH = CRT.attr; /* use the current attribute */
_CH = 0; /* first row - all vars go from 0 to max-1 */
_CL = 0; /* first col */
_DH = CRT.rows-1; /* last row */
_DL = CRT.cols-1; /* last col */
_AX = 0x0600; /* scroll page up service */
geninterrupt (0x10);
goto_rc ( 1,1 ); /* put cursor at 1,1 */
}
void goto_rc ( int row, int col )
{
/* This function positions the cursor to row, col. It also wraps the
cursor around properly after a call to put_string().
*/
if ( col > CRT.cols ) {
row += col / CRT.cols;
col = col % CRT.cols;
}
_BH = 0; /* page 0 only */
_DH = row-1; /* row and col params go from 0 to max-1 */
_DL = col-1;
_AH = 2;
geninterrupt (0x10); /* bios put cursor with AH = 2 */
}
void hide_cursor (void)
{
_CX = 0x2000; /* High Fifth bit set = no cursor */
_AX = 0x0100; /* High Byte =1 = set cursor size */
geninterrupt(0x10);
}
void show_cursor (void)
{
_CX = 0x000d; /* Std Cursor */
_AX = 0x0100; /* High Byte =1 = set cursor size */
geninterrupt(0x10);
}
/* end video.c */